﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

/// <summary>
/// Summary description for QuangCaoCtr
/// </summary>
public class QuangCaoCtr
{
	public QuangCaoCtr()
	{
		
	}
    public DataTable layQuangCao()
    {
        try
        {
            string sql = "select * from QuangCao where TrangThai=1";
            return DataProvider.GetData(sql);
        }
        catch (Exception ex)
        {
            throw ex;
        }

    }

    public EQuangCao layQuangCao(string MaQC)
    {
        try
        {
            DataTable tableQuangCao = DataProvider.GetData("Select * from QuangCao Where MaQC=@MaQC and TrangThai='True'", "@MaQC", MaQC);
            EQuangCao QuangCao = new EQuangCao();
            QuangCao.MaQC = Int32.Parse(tableQuangCao.Rows[0]["MaQC"].ToString());
            QuangCao.TenCongTy = tableQuangCao.Rows[0]["TenCongTy"].ToString();
            QuangCao.HinhAnh = tableQuangCao.Rows[0]["HinhAnh"].ToString();
            QuangCao.LienKet = tableQuangCao.Rows[0]["LienKet"].ToString();
            QuangCao.TrangThai = bool.Parse(tableQuangCao.Rows[0]["TrangThai"].ToString());
            QuangCao.QuanTriVien = tableQuangCao.Rows[0]["QuanTriVien"].ToString();
            return QuangCao;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    public bool InsertQuangCao(EQuangCao QuangCao)
    {
        try
        {
            DataProvider.ExecuteNonQuery("INSERT INTO QuangCao VAlUES(@TenQC,@Hinhanh,@Link,@Tinhtrang,@QuanTri)",
                 "@TenQC", QuangCao.TenCongTy, "@Hinhanh", QuangCao.HinhAnh, "@Tinhtrang", QuangCao.TrangThai, "@QuanTri", QuangCao.QuanTriVien);
            return true;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    public bool DeleteQuangCao(string MaQC)
    {
        try
        {
            DataProvider.ExecuteNonQuery("DELETE FROM QuangCao WHERE MaQC=@MaQC", "@MaQC", MaQC);
            return true;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

    public bool UpdateQuangCao(EQuangCao QuangCao)
    {
        try
        {
            DataProvider.ExecuteNonQuery("Update QuangCao set TenCongTy=@TenCongTy,HinhAnh=@HinhAnh,LienKet=@LienKet,TrangThai=@TrangThai WHERE MaQC=@MaQC", "@MaQC", QuangCao.MaQC, "@TenCongTy",QuangCao.TenCongTy , "@HinhAnh", QuangCao.HinhAnh,"@LienKet",QuangCao.LienKet,"@TrangThai",QuangCao.TrangThai);
            return true;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    //Hanh
    public bool InsertQuangCaoH(EQuangCao QuangCao)
    {
        try
        {
            DataProvider.ExecuteNonQuery("INSERT INTO QuangCao VAlUES(@TenQC,@Hinhanh,@Link,@Tinhtrang,@QuanTri)",
                 "@TenQC", QuangCao.TenCongTy, "@Hinhanh", QuangCao.HinhAnh, "@Tinhtrang", QuangCao.TrangThai, "@QuanTri", QuangCao.QuanTriVien, "@Link", QuangCao.LienKet);
            return true;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    public bool UpdateQuangCaoH(int MaQC, string TenQC, string Hinhanh, string Link, bool Tinhtrang)
    {
        try
        {
            DataProvider.ExecuteNonQuery("Update QuangCao set TenQC=@TenQC,Hinhanh=@Hinhanh,Link=@Link,TrangThai=@Tinhtrang WHERE MaQC=@MaQC", "@MaQC", MaQC, "@TenQC", TenQC, "@Hinhanh", Hinhanh, "@Link", Link, "@Tinhtrang", Tinhtrang);
            return true;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    public EQuangCao layQuangCaoH(string MaQC)
    {
        try
        {
            DataTable tableQuangCao = DataProvider.GetData("Select * from QuangCao Where MaQC=@MaQC and TrangThai='true'", "@MaQC", MaQC);
            EQuangCao QuangCao = new EQuangCao();
            QuangCao.MaQC = Int32.Parse(tableQuangCao.Rows[0]["MaQC"].ToString());
            QuangCao.TenCongTy = tableQuangCao.Rows[0]["TenCongTy"].ToString();
            QuangCao.HinhAnh = tableQuangCao.Rows[0]["HinhAnh"].ToString();
            QuangCao.LienKet = tableQuangCao.Rows[0]["LienKet"].ToString();
            QuangCao.TrangThai = bool.Parse(tableQuangCao.Rows[0]["TrangThai"].ToString());
            QuangCao.QuanTriVien = tableQuangCao.Rows[0]["QuanTriVien"].ToString();
            return QuangCao;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    public bool DeleteQuangCaoH(string MaQC)
    {
        try
        {
            DataProvider.ExecuteNonQuery("DELETE FROM QuangCao WHERE MaQC=@MaQC", "@MaQC", MaQC);
            return true;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    
}